package com.zjsystem.zjsy.controller;

import com.alibaba.fastjson.JSON;
import com.zjsystem.zjsy.request.PlanRequest;
import com.zjsystem.zjsy.request.StageInfoRequest;
import com.zjsystem.zjsy.result.Result;
import com.zjsystem.zjsy.service.ZjxdPlanService;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 筹划方案监控表 前端控制器
 * </p>
 *
 * @author wyf
 * @since 2024-07-11
 */
@Slf4j
@RestController
@RequestMapping("/zjsy/zjxdPlan")
public class ZjxdPlanController {

    @Resource
    private ZjxdPlanService planService;

    @ApiModelProperty("创建中 下发任务 创建筹划方案表")
    @PostMapping("/savePlan")
    public Result savePlan(@RequestBody PlanRequest request) {
        try {
            planService.savePlan(request);
            return Result.ok().message("任务下发成功");
        } catch (Exception e) {
            log.error("任务下发异常：{}", e.getMessage());
            throw new RuntimeException(e.getMessage());
        }
    }

    @ApiModelProperty("筹划监控 列表展示接口")
    @PostMapping("/getPlanInfo")
    public Result getPlanInfo(@RequestBody StageInfoRequest request) {
        try {
            return planService.getPlanInfo(request.getId(), request.getStatus());
        } catch (Exception e) {
            log.error("筹划监控 列表展示接口 异常：{}", e.getMessage());
            return Result.fail().message("操作异常 请联系开发人员检测");
        }
    }

    @ApiModelProperty("筹划监控 驳回/通过按钮")
    @PostMapping("/returnOrPassButton")
    public Result returnOrPassButton(@RequestBody StageInfoRequest request) {
        log.info("筹划监控 驳回/通过 入参为：{}", JSON.toJSONString(request));
        try {
            planService.returnOrPassButton(request);
            return Result.ok().message("操作成功");
        } catch (Exception e) {
            log.error("筹划监控 驳回/通过按钮 异常：{}", e.getMessage());
            throw new RuntimeException("操作异常 请联系开发人员检测");
        }
    }


}

